COOKIEFILE=cookie.file
URL=http://www.1channel.ch/tv-9920-Dragons-Den/season-10-episode-2	
	
	Pageinit=$(cat sitepage)

	IFS=$'\n'
	Links=( $(echo "$Pageinit" | grep 'external.php' ) )
	Sites=( $(echo "$Pageinit" | grep 'document.writeln') )

echo ${#Links[@]}
echo ${#Sites[@]}

initarray ()
{
  for (( i=0; i < ${#Sites[@]}; i++ )) do
      Sites[i]=${Sites[i]:141}
      Sites[i]=${Sites[i]%??????????????????????????}
      Sites[i]+=$'\n'
  done
} 

formatarray ()
{
  for (( i=0; i < ${#Sites[@]}; i++ )) do
      Sites[i]+=$'\n'
  done
} 
    
  initarray
  echo ${Sites[@]}
	for (( i=1; i < $((${#Sites[@]}+1)); i++ )) do
        # echo i=$i "${Sites[$((i-1))]}"
       if [ $(echo "${Sites[$((i-1))]}") = "HD Sponsor" ] || [ $(echo "${Sites[$((i-1))]}") = " HD Sponsor" ] || [ $(echo "${Sites[$((i-1))]}") = "  HD Sponsor" ]; then
          echo hdsponsor=$i
          if [ $i = 1 ]; then
            Sites=( ${Sites[@]:1} )
            formatarray
            # echo ${Sites[@]}
            i=0
          fi
          if [[ $i > 1 ]]; then
            echo ${Sites[@]}
            echo HDSPONSORi=$i 
            echo ${Sites[@]:0:$((i-1))}
            echo ${Sites[@]:$(($i))}
            Sites=(${Sites[@]:0:$((i-1))} ${Sites[@]:$(($i))})
            formatarray
            i=0
            echo ${Sites[@]}
          fi
       fi
       echo i=$i
      
  done

  echo ${Sites[@]} 